<div id="content">

    <? if(is_array($response)){?>
        <div class="response">
            <span class="<?=$response["class"]?>"><?=$response["msg"]?></span>
        </div>
    <?}?>

    <? if (($this->input->post("submit_action") !== FALSE) && (validation_errors()!="")){ ?>
        <div class="response"><?=validation_errors()?></div>                
    <? } ?>

    <h1><?=$this->lang->line('Members_Program')?> - Advanced search</h1>

    <div class="live_search_msg"></div>    

    <form action="" method="post">

    <div style="overflow:auto; border-bottom: 1px dashed #CCC; width:640px">
        <div class="content_block" style="width:180px; float:left">

            <h4>Search for:</h4>
            <input type="text" name="string" style="width:175px; margin-bottom:20px" value="<?=set_value('string', $string)?>" />

            <h4>Order by:</h4>
            <select style="width:180px; margin-bottom:20px" name="order">
                <option value="DateJoined_UsersDetails DESC" <?=set_select('order', 'DateJoined_UsersDetails DESC', ($order=='DateJoined_UsersDetails DESC')); ?> />Date registered</option>
                <option value="LastLogin_UsersDetails DESC" <?=set_select('order', 'LastLogin_UsersDetails DESC', ($order=='LastLogin_UsersDetails DESC')); ?> />Last login</option>
                <option value="NumberLogins_UsersDetails DESC" <?=set_select('order', 'NumberLogins_UsersDetails DESC', ($order=='NumberLogins_UsersDetails DESC')); ?> />Number of logins</option>
                <option value="DateDeactivated_UsersDetails DESC" <?=set_select('order', 'DateDeactivated_UsersDetails DESC', ($order=='DateDeactivated_UsersDetails DESC')); ?> />Date deactivated</option>
                <option value="FirstName_UsersDetails" <?=set_select('order', 'FirstName_UsersDetails', ($order=='FirstName_UsersDetails')); ?> />Name</option>
                <option value="LastName_UsersDetails" <?=set_select('order', 'LastName_UsersDetails', ($order=='LastName_UsersDetails')); ?> />Surname</option>
            </select>

            <input type="submit" class="button" name="submit_action" value="SEARCH" />

        </div>

        <div class="content_block" style="width:420px; margin-left:220px; clear:right">
            <h4>Search in:</h4>
            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="FirstName_UsersDetails" <?=set_checkbox('fields[]', 'FirstName_UsersDetails', (in_array('FirstName_UsersDetails', $fields))); ?> />
                Name
            </label>
            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="CompanyName_UsersDetails" <?=set_checkbox('fields[]', 'CompanyName_UsersDetails', (in_array('CompanyName_UsersDetails', $fields))); ?> />
                Company name
            </label>
            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="LastName_UsersDetails" <?=set_checkbox('fields[]', 'LastName_UsersDetails', (in_array('LastName_UsersDetails', $fields))); ?> />
                Surname
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="Address_UsersDetails" <?=set_checkbox('fields[]', 'Address_UsersDetails', (in_array('Address_UsersDetails', $fields))); ?> />
                Address                                                                                                              
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="Email_UsersDetails" <?=set_checkbox('fields[]', 'Email_UsersDetails', (in_array('Email_UsersDetails', $fields))); ?> />
                Email
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="ZipCode_UsersDetails" <?=set_checkbox('fields[]', 'ZipCode_UsersDetails', (in_array('ZipCode_UsersDetails', $fields))); ?> />
                ZIP/Postal code
            </label>


            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="DaytimePhone_UsersDetails" <?=set_checkbox('fields[]', 'DaytimePhone_UsersDetails', (in_array('DaytimePhone_UsersDetails', $fields))); ?> />
                Phone number
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="City_UsersDetails" <?=set_checkbox('fields[]', 'City_UsersDetails', (in_array('City_UsersDetails', $fields))); ?> />
                City
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="Mobile_UsersDetails" <?=set_checkbox('fields[]', 'Mobile_UsersDetails', (in_array('Mobile_UsersDetails', $fields))); ?> />
                Mobile phone
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="State_UsersDetails" <?=set_checkbox('fields[]', 'State_UsersDetails', (in_array('State_UsersDetails', $fields))); ?> />
                State/County
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="ProfessionalDesignations" <?=set_checkbox('fields[]', 'ProfessionalDesignations', (in_array('ProfessionalDesignations', $fields))); ?> />
                Professional designation
            </label>

            <label style="display:block; width:200px; float:left; margin-right:10px">
                <input type="checkbox" name="fields[]" value="Country_UsersDetails" <?=set_checkbox('fields[]', 'Country_UsersDetails', (in_array('Country_UsersDetails', $fields))); ?> />
                Country
            </label>

        </div>
    </div>
    
    </form>


    <? if ($string !== ""){ ?>

       <h3 style="margin-top:20px">Found <?=count($list)?> results for <i><?=$string?></i></h3>

    <? } ?>
        
    <?

    $maxresults = 100;

    if (count($list) > $maxresults ) {?>

        <span class="warning" style="margin-bottom:20px">Found too many results to display them all, here are the first <?=$maxresults?>.<br />Please narrow your search for a more accurate result.</span>

    <? } ?>

    <?
        $i = 0;
        while(($i<$maxresults) && (list($key, $item) = each($list))){ 

        //$item = $list[$i];
        //$class = ($item['Active_Users']=='1')?'active':'inactive';
    ?>

        <div class="list_block search <?//=$class?>">

            <a class="title" href="<?=site_url('admin/insiders/preview/'.$item['id_Users'])?>" rel="view">
                <?=highlight($string, $item['name'])?> 
                <?=highlight($string, $item['surname'])?> 
            </a>



            <div class="clear" style="margin-left:80px; font-size:10px; line-height:14px;">

              <div style="float:right; margin-left: 10px; width:200px"

                <? if(array_key_exists('DateJoined_UsersDetails', $item)) {?>
                <div class="clear">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Registration date</h4>
                    <?=date("d/m/Y",strtotime($item['DateJoined_UsersDetails']))?><br />
                </div>
                <? } ?>

                <? if(array_key_exists('LastLogin_UsersDetails', $item)) {?>
                <div class="clear">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Last login</h4>
                    <?=date("d/m/Y",strtotime($item['LastLogin_UsersDetails']))?>
                </div>
                <? } ?>

                <? if(array_key_exists('NumberLogins_UsersDetails', $item)) {?>
                <div class="clear">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Number of logins</h4>
                    <?=$item['NumberLogins_UsersDetails']?>
                </div>
                <? } ?>

              </div>
                
                <? if(array_key_exists('Email_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Email</h4>
                    <?=highlight($string, $item['Email_UsersDetails'])?>
                </div>
                <? } ?>

                <? if(array_key_exists('DaytimePhone_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Phone number</h4>
                    <?=highlight($string, $item['DaytimePhone_UsersDetails'])?>
                </div>
                <? } ?>                  

                <? if(array_key_exists('Mobile_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Mobile phone</h4>
                    <?=highlight($string, $item['Mobile_UsersDetails'])?> 
                </div>
                <? } ?>

                <? if(array_key_exists('ProfessionalDesignations', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Prof. designation</h4>
                    <?=highlight($string, $item['ProfessionalDesignations'])?>
                </div>
                <? } ?>

                <? if(array_key_exists('CompanyName_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Company name</h4>
                    <?=highlight($string, $item['CompanyName_UsersDetails'])?>
                </div>
                <? } ?>

                <? if(array_key_exists('Address_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Address</h4>
                    <?=highlight($string, nl2br($item['Address_UsersDetails']))?> 
                </div>
                <? } ?>

                <? if(array_key_exists('State_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">City</h4>
                    <?=highlight($string, $item['State_UsersDetails'])?>
                </div>
                <? } ?>

                <? if(array_key_exists('LastName_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">State/Province</h4>
                    <?=highlight($string, $item['LastName_UsersDetails'])?>
                </div>                
                <? } ?>

                <? if(array_key_exists('ZipCode_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">ZIP/Postal Code</h4>
                    <?=highlight($string, $item['ZipCode_UsersDetails'])?>
                </div>
                <? } ?>

                <? if(array_key_exists('Country_UsersDetails', $item)) {?>
                <div style="float:left; clear:left; width:380px">
                    <h4 style="display: block; float: left; width: 110px; font-size: 10px;">Country</h4>
                    <?=highlight($string, $item['Country_UsersDetails'])?>
                </div>
                <? } ?>

            </div>

        </div>

        <? $i++; ?>

    <? } ?>

                
    <pre>
    <?// if (!empty($list)) print_r($list);?>
    </pre>

</div>